package com.hznc.wcs.controller.bpm;

import com.diboot.core.vo.JsonResult;
import com.diboot.core.vo.Pagination;
import com.diboot.iam.annotation.BindPermission;
import com.diboot.iam.annotation.Log;
import com.diboot.iam.annotation.OperationCons;
import com.hznc.wcs.service.bpm.BpmProcessDefinitionService;
import com.hznc.wcs.vo.bpm.BpmProcessDefinitionReqVO;
import com.hznc.wcs.vo.bpm.BpmProcessDefinitionRespVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description : 流程定义接口
 * @Date : 2024/6/24
 * @Author : ChenJin
 * @Version : v1.0.0
 **/
@Slf4j
@RestController
@BindPermission(name = "流程定义",code = "BpmDefinition")
@RequestMapping("/bpm-definition")
public class BpmDefinitionController {
    
    @Resource
    private BpmProcessDefinitionService bpmProcessDefinitionService;

    /**
     * 查询可发起流程(已部署)的流程实例列表
     * @param reqVO
     * @param pagination
     * @return
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_LIST)
    @BindPermission(name = OperationCons.LABEL_LIST, code = OperationCons.CODE_READ)
    @GetMapping("/getDefinitionPage")
    public JsonResult<?> getDefinitionPage(BpmProcessDefinitionReqVO reqVO, Pagination pagination){
        //获取可发起流程的流程定义,即活动的流程定义
        List<BpmProcessDefinitionRespVO> definitionList = bpmProcessDefinitionService.getBpmProcessDefinitionList(reqVO, pagination);
        return JsonResult.OK(definitionList).bindPagination(pagination);
    }

    @Log(operation = OperationCons.LABEL_LIST)
    @BindPermission(name = OperationCons.LABEL_LIST, code = OperationCons.CODE_WRITE)
    @GetMapping("/getDefinitionList")
    public JsonResult<?> getDefinitionList(BpmProcessDefinitionReqVO reqVO){
        //获取可发起流程的流程定义,即活动的流程定义
        List<BpmProcessDefinitionRespVO> definitionList = bpmProcessDefinitionService.getBpmProcessDefinitionList(reqVO,null);
        return JsonResult.OK(definitionList);
    }
    
    @Log(operation = OperationCons.LABEL_DETAIL)
    @BindPermission(name = OperationCons.LABEL_DETAIL, code = OperationCons.CODE_READ)
    @GetMapping("/getDefinitionInfo/{id}")
    public JsonResult<?> getDefinitionInfo(@PathVariable("id") String id){
        //获取可发起流程的流程定义,即活动的流程定义
        BpmProcessDefinitionRespVO bpmProcessDefinitionRespVO = bpmProcessDefinitionService.getBpmProcessDefinition(id);
        return JsonResult.OK(bpmProcessDefinitionRespVO);
    }
    
}
